// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Collections;
using System.Text;
using System.Xml;

using QuoteAdvantageEditor.CrmSdk;

namespace QuoteAdvantageEditor
{
	/// <summary>
	/// Summary description for Product.
	/// </summary>
	public class Product
	{
      private string    m_strCategoryId;  // Not tracked by database. This is used for adding QuoteDetails.
      private Guid      m_guidDefaultUnitOfMeasureId;
      private string    m_strDescription;
      private bool      m_bIsKit;
      private string    m_strName;
      private Guid      m_guidProductId;
      private string    m_strProductNumber;
      private Decimal   m_nPrice;
      private Guid      m_guidDefaultUomScheduleId;

		public Product()
		{
			
		}

      // Not tracked by database. This is used for adding QuoteDetails.
      public string CategoryId
      {
         get { return m_strCategoryId;}
         set { m_strCategoryId = value;}
      }
     
      public Guid DefaultUnitOfMeasureId
      {
         get { return m_guidDefaultUnitOfMeasureId;}
         set { m_guidDefaultUnitOfMeasureId = value;}
      }
      
      public string Description
      {
         get { return m_strDescription;}
         set { m_strDescription = value;}
      }

      public string Name
      {
         get { return m_strName;}
         set { m_strName = value;}
      }
    
      public bool IsKit
      {
         get { return m_bIsKit;}
         set { m_bIsKit = value;}
      }
      
      public Decimal Price
      {
         get { return m_nPrice;}
         set { m_nPrice = value;}
      }

      public Guid ProductId
      {
         get { return m_guidProductId;}
         set { m_guidProductId = value;}
      }
      
      public string ProductNumber
      {
         get { return m_strProductNumber;}
         set { m_strProductNumber = value;}
      }

      public Guid DefaultUomScheduleId
      {
         get { return m_guidDefaultUomScheduleId;}
         set { m_guidDefaultUomScheduleId = value;}
      }
      


      public Product Clone()
      {
         Product  objNewProduct = new Product();

         objNewProduct.CategoryId = m_strCategoryId;  
         objNewProduct.DefaultUnitOfMeasureId = m_guidDefaultUnitOfMeasureId;
         objNewProduct.DefaultUomScheduleId = m_guidDefaultUomScheduleId;
         objNewProduct.Description = m_strDescription;
         objNewProduct.IsKit = m_bIsKit;
         objNewProduct.Name = m_strName;
         objNewProduct.ProductId = m_guidProductId;
         objNewProduct.ProductNumber = m_strProductNumber;
         objNewProduct.Price = m_nPrice;  
 
         return objNewProduct;
      }
                      
      public void LoadFromCrmProduct(product objCrmProduct)
      {
         this.DefaultUnitOfMeasureId = objCrmProduct.defaultuomid.Value;
         this.Description = objCrmProduct.description;
         this.IsKit = objCrmProduct.iskit.Value;
         this.Name = objCrmProduct.name;

         if (objCrmProduct.price == null)
         {
            this.Price = 0;
         }
         else
         {
            this.Price = objCrmProduct.price.Value;
         }

         this.ProductId = objCrmProduct.productid.Value;
         this.ProductNumber = objCrmProduct.productnumber; 

         if (objCrmProduct.defaultuomscheduleid == null)
         {
            this.DefaultUomScheduleId = Guid.Empty;
         }
         else
         {
            this.DefaultUomScheduleId = objCrmProduct.defaultuomscheduleid.Value;
         }
      }

	} // end class
}
